package com.xing.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mysql.cj.x.protobuf.Mysqlx;
import com.xing.commonutils.R;
import com.xing.educms.entity.CrmBanner;
import com.xing.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  后台bannner管理接口
 * </p>
 *
 * @author xingfuao
 * @since 2022-03-20
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin //允许跨域
public class BannerAdminController {

    @Autowired
     CrmBannerService bannerService;

    //1.分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<>(page, limit);
        bannerService.page(pageBanner,null);
        return R.ok()
                .data("items",pageBanner.getRecords())
                .data("total",pageBanner.getTotal());
    }

    //2 添加 banner
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }

    @PutMapping("update")
    public R updateById(@RequestBody CrmBanner crmBanner){
        bannerService.updateById(crmBanner);
        return R.ok();
    }

    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }

    @GetMapping("get/{id}")
    public R get(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item",banner);
    }


}

